// 首页高亮
const xtxHomepage = document.querySelector('.xtxHomepage div:nth-child(2) ul')
xtxHomepage.addEventListener('click', function (e) {
    if (e.target.tagName === 'A') {
        document.querySelector('.xtxHomepage div:nth-child(2) ul a.active').classList.remove('active')
        e.target.classList.add('active')
    }
})





// 鼠标经过购物车显示购物车页面
const xtxPageCar = document.querySelector('.disabled')
xtxPageCar.addEventListener('mouseover', function () {
    document.querySelector('.xtxHomepage .box').style.display = 'block'
})

xtxPageCar.addEventListener('mouseout', function () {
    document.querySelector('.xtxHomepage .box').style.display = 'none'
})

// 点击删除实现删除购物车功能
const deletet = document.querySelectorAll('.disabled .item i')
for (let i = 0; i < deletet.length; i++) {
    deletet[i].addEventListener('click', function () {
        document.querySelector('.disabled .item').remove()
    })
}

const li1 = document.querySelector('.xtxLogin li:nth-child(1)')
const li2 = document.querySelector('.xtxLogin li:nth-child(2)')

function render() {
    const uname = localStorage.getItem('text')
    if (uname) {
        li1.innerHTML = `<a href="./login.html"><i class="iconfont icon-xiaoren"></i>${uname}</a>`
        li2.innerHTML = `<a href="#">退出登录</a>`
    } else {
        li1.innerHTML = `<a href="./login.html">请先登录</a>`
        li2.innerHTML = `<a href="./register.html">免费注册</a>`
    }
}
render()
li2.addEventListener('click', function () {
    localStorage.removeItem('text')
    render()
})